include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <stack>
using namespace std;

class bag
{
public:
	void backtracking(vector<int>&weight, vector<int>&value, int bagWeight, int startindex, int curbagvalue,int curbagweight)
	{
		if (curbagweight <= bagWeight && curbagvalue > maxvalue)
		{
			maxvalue = curbagvalue;
			result = temp;
			//因为这里要继续往后找,所以不return
		}
		if (curbagweight > bagWeight)
			return;
		for (int i = startindex; i < weight.size(); i++)
		{
			temp.push_back(i);
			curbagvalue += value[i];
			curbagweight += weight[i];
			backtracking(weight, value, bagWeight, i+1 ,curbagvalue, curbagweight); 
			temp.pop_back();
			curbagweight -= weight[i];
			curbagvalue -= value[i];
		}
	}
	vector<int> wei_bag_problem1(vector<int>&weight, vector<int>&value, int bagWeight)
	{
		maxvalue = 0;
		backtracking(weight, value, bagWeight, 0, 0, 0);
		return result;
	}
	vector<int> result;
	vector<int> temp;
	int maxvalue;
};




int main()
{
	vector<int> weight = { 1, 3 ,  4 , 5, 6, 7}; //物品重量
	vector<int> value = { 15, 20, 30 ,40,50,70}; //物品价值 
	int bagWeight = 8; //背包大小

	bag b;
	vector<int> result =  b.wei_bag_problem1(weight, value, bagWeight);

	system("pause");
	return 0;
}